package enumdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—23
 * Time: 16:28
 */
public enum enumDemo01 {
    ONE,TWE("twe",2),TREE;//枚举对象

    public String figure;
    public int ordinal;
    //枚举的构造方法默认是私有的
    enumDemo01(String figure, int ordinal) {
        this.figure = figure;
        this.ordinal = ordinal;
    }
    enumDemo01() {
    }

    public static void main(String[] args) {
        //拿到枚举实例TWE
        enumDemo01 e1 = enumDemo01.TWE;
        //拿到枚举实例TREE
        enumDemo01 e2 = enumDemo01.TREE;
        //比较的是序号
        System.out.println(enumDemo01.TREE.compareTo(e1));
        System.out.println(ONE.compareTo(TWE));
        System.out.println(ONE.compareTo(TREE));
    }
    public static void main2(String[] args) {
        enumDemo01[] enumDemo01s = enumDemo01.values();
        for (int i = 0; i < enumDemo01s.length; i++) {
            System.out.println(enumDemo01s[i] + " 序号：" + enumDemo01s[i].ordinal());
        }

        enumDemo01 e1 = enumDemo01.valueOf("TREE");
        System.out.println(e1);

    }
    public static void main1(String[] args) {
        enumDemo01 enumDemo01 = enumdemo.enumDemo01.TWE;
        switch (enumDemo01) {
            case ONE:
                System.out.println("1");
                break;
            case TWE:
                System.out.println("2");
                break;
            case TREE:
                System.out.println("3");
                break;
            default:
                break;
        }
    }
}
